package gui.mainWindow.scores;

import gui.mainWindow.MainWindow;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class ScoresActionListener implements ActionListener {
	private final MainWindow window;

	public ScoresActionListener(MainWindow mainWindow) {
		this.window = mainWindow;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		this.window.getScoresParticipantNameDropDown().removeActionListener(this);
		this.window.getScoresTargetCharDropDown().removeActionListener(this);
		this.window.getScoresTargetNumberDropDown().removeActionListener(this);

		if (arg0.getSource() == this.window.getScoresTargetNumberDropDown()) {
			this.window.getScoresController().buildTargetCharDropDown();
			this.window.getScoresController().setAccordingPlayerSelected();
		}
		if (arg0.getSource() == this.window.getScoresTargetCharDropDown()) {
			this.window.getScoresController().setAccordingPlayerSelected();
		}
		if (arg0.getSource() == this.window.getScoresParticipantNameDropDown()) {
			this.window.getScoresController().setAccordingTargetSelected();
		}
		this.window.getScoresController().setDetailledArcherInformation();

		try {
			this.window.getScoresController().buildScoresTable();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		this.window.getScoresTargetNumberDropDown().addActionListener(this);
		this.window.getScoresParticipantNameDropDown().addActionListener(this);
		this.window.getScoresTargetCharDropDown().addActionListener(this);
	}
}
